#ifndef _easy_sock_H_
#define _easy_sock_H_

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <mlog.h>
#include <appdef.h>

/*
sock_fd     socket hangdle
rflag       when 1 read proces is ready to exit
sflag       when 1 send proces is ready to exit
PTHREADS     a list of threads that process this connection
mutex_sock_buf  a lock of sock buffer
length          message length ready to send
buf        a buffer ready to send
*/
typedef struct sock_stru{
int sock_fd;
int rflag;
int sflag;
pthread_mutex_t buf_lock;
unsigned int length;
char sbuf[BUF_LEN];
}MSOCK;

#define PCHECK( func, funcname ) {  \
    if((func) == -1 )               \
    {                               \
         perror(funcname);          \
         return -1;                 \
    }                               \
}

#ifdef __cplusplus
extern "C" {
#endif

int open_listen(short);
void makesockaddr(struct sockaddr_in *,const char *,const short);
int connect_to(const char *ip, const short port);
int init_msock( int , MSOCK **);
int close_sock(MSOCK *);

#ifdef __cplusplus
}
#endif

#endif
